﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_InHoaDon : System.Web.UI.Page
{
    private DataSet objDataSet;

    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        if (id != "")
        {
            PopulateControls();
        }
    }

    // populate the form with data
    private void PopulateControls()
    {
        // obtain order ID from the session
        string orderId = Session["AdminOrderID"].ToString();
        // obtain order info
        DonDatHangBUS OrdersAccess =
            new DonDatHangBUS(TGDDConfiguration.DbConnectionString);
        objDataSet = OrdersAccess.GetInfoDonDatHang(int.Parse(orderId));
        DataRow row = objDataSet.Tables[0].Rows[0];
        DonDatHangDTO orderInfo = new DonDatHangDTO();
        orderInfo.Id = int.Parse(row["id"].ToString());
        orderInfo.ThanhTien = long.Parse(row["ThanhTien"].ToString());
        orderInfo.NgayDatHang = DateTime.Parse(row["NgayDatHang"].ToString());

        if (!row["NgayGiaoHang"].ToString().Equals(""))
        {
            orderInfo.NgayGiaoHang = DateTime.Parse(row["NgayGiaoHang"].ToString());
            lblNgayGiaoHang.Text = orderInfo.NgayGiaoHang.ToString();
        }
        else
        {
            lblNgayGiaoHang.Text = "";
        }
        orderInfo.XacNhan = bool.Parse(row["XacNhan"].ToString());
        orderInfo.DaGiao = bool.Parse(row["DaGiao"].ToString());
        orderInfo.GhiChu = row["GhiChu"].ToString();
        orderInfo.TenKhachHang = row["TenKhachHang"].ToString();
        orderInfo.DiaChiNguoiNhan = row["DiaChiNguoiNhan"].ToString();
        // populate labels and text boxes with order info
        orderIdLabel.Text = "Hiển thị đơn đặt hàng #" + orderId;
        totalAmountLabel.Text = String.Format("{0:#,##0;Nothing}", orderInfo.ThanhTien);
        lblNgayDatHang.Text = orderInfo.NgayDatHang.ToString();
        //dateShippedTextBox.Text = orderInfo.NgayGiaoHang.ToString();
        verifiedCheck.Checked = orderInfo.XacNhan;
        completedCheck.Checked = orderInfo.DaGiao;
        lblGhiChu.Text = orderInfo.GhiChu;
        lblTenKhachHang.Text = orderInfo.TenKhachHang;
        lblDiaChiNguoiNhan.Text = orderInfo.DiaChiNguoiNhan;
        // by default the Edit button is enabled, and the
        // Update and Cancel buttons are disabled
        // Decide which one of the other three buttons
        // should be enabled and which should be disabled

        // fill the data grid with order details
        objDataSet = OrdersAccess.GetDetailsDonDatHang(int.Parse(orderId));
        grid.DataSource = objDataSet.Tables[0];
        grid.DataBind();
    }
    protected void btnInHoaDon_Click(object sender, EventArgs e)
    {
        Page.Controls.Add(new LiteralControl(
         "<script language='javascript'>CallPrint('hoadonmuahang');</script>"));
    }
}
